<?php

namespace app\api\controller\v1;

use app\common\controller\BaseController;
use app\common\validate\ReceiverValidate;
use app\common\model\Receiver as ReceiverModel;

class Receiver extends BaseController
{
    // 前置操作
    protected $beforeActionList = [
        'isCurrentUser'  =>  ['only'=>'complete'],
    ];

    // 检测操作的是否为当前用户的数据
    protected function isCurrentUser()
    {
        // 验证
        (new ReceiverValidate())->goCheck('isCurrentUser');
        $r = (new ReceiverModel())->isCurrentUser();
        if(!$r) {
            self::interrupt('不可操作他人的数据');
        }
    }

    // 完成订单
    public function complete()
    {
        // 验证
        (new ReceiverValidate())->goCheck('complete');
        (new ReceiverModel())->complete();
        return self::showResCodeWithOutData('操作成功');
    }
}
